Conditions | 6 |
Paths | 5 |
Total Lines | 68 |
Code Lines | 46 |
Lines | 67 |
Ratio | 98.53 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** global: appSettings */ |
||
19 | View Code Duplication | ipcRenderer.on('bw:fileinput.confirmation', function(event, filePath = null, isDragDrop = false) { |
|
|
|||
20 | const { |
||
21 | misc, |
||
22 | lookup |
||
23 | } = appSettings; |
||
24 | var bwFileStats; // File stats, size, last changed, etc |
||
25 | |||
26 | //console.log(filePath); |
||
27 | if (filePath === undefined || filePath == '' || filePath === null) { |
||
28 | //console.log(filePath); |
||
29 | $('#bwFileinputloading').addClass('is-hidden'); |
||
30 | $('#bwEntry').removeClass('is-hidden'); |
||
31 | } else { |
||
32 | $('#bwLoadingInfo').text('Loading file stats...'); |
||
33 | if (isDragDrop === true) { |
||
34 | $('#bwEntry').addClass('is-hidden'); |
||
35 | $('#bwFileinputloading').removeClass('is-hidden'); |
||
36 | bwFileStats = fs.statSync(filePath); |
||
37 | bwFileStats['filename'] = filePath.replace(/^.*[\\\/]/, ''); |
||
38 | bwFileStats['humansize'] = conversions.byteToHumanFileSize(bwFileStats['size'], misc.usestandardsize); |
||
39 | $('#bwFileSpanInfo').text('Loading file contents...'); |
||
40 | bwFileContents = fs.readFileSync(filePath); |
||
41 | } else { |
||
42 | bwFileStats = fs.statSync(filePath[0]); |
||
43 | bwFileStats['filename'] = filePath[0].replace(/^.*[\\\/]/, ''); |
||
44 | bwFileStats['humansize'] = conversions.byteToHumanFileSize(bwFileStats['size'], misc.usestandardsize); |
||
45 | $('#bwFileSpanInfo').text('Loading file contents...'); |
||
46 | bwFileContents = fs.readFileSync(filePath[0]); |
||
47 | } |
||
48 | $('#bwFileSpanInfo').text('Getting line count...'); |
||
49 | bwFileStats['linecount'] = bwFileContents.toString().split('\n').length; |
||
50 | |||
51 | if (lookup.randomize.timebetween === true) { |
||
52 | bwFileStats['minestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.randomize.timebetweenmin); |
||
53 | bwFileStats['maxestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.randomize.timebetweenmax); |
||
54 | |||
55 | $('#bwFileSpanTimebetweenmin').text('{0}ms '.format(lookup.randomize.timebetweenmin)); |
||
56 | $('#bwFileSpanTimebetweenmax').text('/ {0}ms'.format(lookup.randomize.timebetweenmax)); |
||
57 | $('#bwFileTdEstimate').text('{0} to {1}'.format(bwFileStats['minestimate'], bwFileStats['maxestimate'])); |
||
58 | } else { |
||
59 | bwFileStats['minestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.timebetween); |
||
60 | $('#bwFileSpanTimebetweenminmax').addClass('is-hidden'); |
||
61 | $('#bwFileSpanTimebetweenmin').text(lookup.timebetween + 'ms'); |
||
62 | $('#bwFileTdEstimate').text('> {0}'.format(bwFileStats['minestimate'])); |
||
63 | } |
||
64 | |||
65 | |||
66 | |||
67 | bwFileStats['filepreview'] = bwFileContents.toString().substring(0, 50); |
||
68 | //console.log(readLines(filePath[0])); |
||
69 | //console.log(bwFileStats['filepreview']); |
||
70 | |||
71 | //console.log(lineCount(bwFileContents)); |
||
72 | $('#bwFileinputloading').addClass('is-hidden'); |
||
73 | $('#bwFileinputconfirm').removeClass('is-hidden'); |
||
74 | |||
75 | // stats |
||
76 | $('#bwFileTdName').text(bwFileStats['filename']); |
||
77 | $('#bwFileTdLastmodified').text(bwFileStats['mtime']); |
||
78 | $('#bwFileTdLastaccess').text(bwFileStats['atime']); |
||
79 | $('#bwFileTdFileSize').text(bwFileStats['humansize'] + ' ({0} line(s))'.format(bwFileStats['linecount'])); |
||
80 | $('#bwFileTdFilepreview').text(bwFileStats['filepreview'] + '...'); |
||
81 | //$('#bwTableMaxEstimate').text(bwFileStats['maxestimate']); |
||
82 | //console.log('cont:'+ bwFileContents); |
||
83 | |||
84 | //console.log(bwFileStats['linecount']); |
||
85 | } |
||
86 | }); |
||
87 | |||
176 |